package org.zl.mybatis.use.intercept;

import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Signature;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;

/**
 * Executor下拦截器
 * @author ben
 * @date 2021-11-30 21:01:43 CST
 */
@Intercepts({
	@Signature(type = Executor.class,
			method = "update",
			args = {MappedStatement.class, Object.class}),
	@Signature(type = Executor.class,
			method = "query",
			args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}),
	@Signature(type = Executor.class,
			method = "queryCursor",
			args = {MappedStatement.class, Object.class, RowBounds.class}),
	
})
public class ExecutorUpdateInterceptor implements Interceptor {

	@Override
	public Object intercept(Invocation invocation) throws Throwable {
		System.out.println("\n-------1\n" + invocation);
		System.out.println(invocation.getTarget());
		System.out.println(invocation.getMethod());
		System.out.println(invocation.getArgs() + "\n-------");
		
		Object ret = invocation.proceed();
		return ret;
	}

}
